* Stata code for the General Social Survey analysis in 
* L.J Zigerell
* Left Unchecked: Political Hegemony in Political Science and the Flaws It Can Cause
* PS: Political Science & Politics

set maxvar 9000
use "F:GSS7218_R1.DTA"

* Limit analysis to 2000 to 2018
tab year fejobaff
drop if year < 2000
tab year fejobaff, mi

* Code outcome variable (as measured)
tab fejobaff
tab fejobaff, nol
gen feaffFAVOR01 = (4-fejobaff)/3
tab fejobaff feaffFAVOR01, mi

* Code outcome variable (dichotomous)
tab fejobaff
tab fejobaff, nol
gen fejobFAVOR2 = fejobaff
recode fejobFAVOR2 (1 2=1) (3 4=0)
tab fejobaff fejobFAVOR2, mi

* Code party ID
tab partyid
tab partyid, nol mi
gen gop7 = partyid
recode gop7 (7=.)
gen gop01 = gop7/6
tab partyid gop01, mi
gen dem01 = 1 - gop01
tab partyid dem01, mi

* Code ideology
tab polviews
tab polviews, nol
gen lib01 = (7-polviews)/6
tab polviews lib01, mi

* Code controls
tab sex
tab sex, nol
gen female = sex - 1
tab sex female

tab race
tab race, gen(RACEV)
rename RACEV1 Rwhite
rename RACEV2 Rblack
rename RACEV3 Rother
tab race Rwhite
tab race Rblack
tab race Rother

sum age
gen age01 = (age-18)/(89-18)
sum age01
pwcorr age age01

tab educ
gen educ01 = educ/20
tab educ01
pwcorr educ educ01

sum           feaffFAVOR01 lib01 female Rwhite Rblack Rother age01 educ01

* set the svyset option
* see here for a description of why to use "singleunit(centered)": http://www.stata.com/statalist/archive/2011-12/msg00397.html
* singleunit(centered) is necessary because standard errors will not be reported otherwise
svyset vpsu [pw=wtssall], strata(vstrat) singleunit(centered)

* Make sure no oversample cases
tab sample
tab sample, nol
drop if sample==4 | sample==5 | sample==7

* Analysis (dichotomous outcome variable)

logit      fejobFAVOR2 dem01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
svy: logit fejobFAVOR2 dem01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
margins, atmeans at(dem01=(0(1)1))

logit      fejobFAVOR2 dem01 female Rwhite Rblack age01 educ01 if year==2018
svy: logit fejobFAVOR2 dem01 female Rwhite Rblack age01 educ01 if year==2018
margins, atmeans at(dem01=(0(1)1))

logit      fejobFAVOR2 lib01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
svy: logit fejobFAVOR2 lib01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
margins, atmeans at(lib01=(0(1)1))

logit      fejobFAVOR2 lib01 female Rwhite Rblack age01 educ01 if year==2018
svy: logit fejobFAVOR2 lib01 female Rwhite Rblack age01 educ01 if year==2018
margins, atmeans at(lib01=(0(1)1))

* Analysis (non-dichotomous outcome variable)

svy: reg           feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
margins, atmeans at(dem01=(0(1)1))
svy: fracreg logit feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
svy: ologit        feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
svy: mlogit        feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018

svy: reg           feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
margins, atmeans at(lib01=(0(1)1)) 
svy: fracreg logit feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
svy: ologit        feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
svy: mlogit        feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018

svy: reg           feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year==2018
margins, atmeans at(dem01=(0(1)1))
svy: fracreg logit feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year==2018
svy: ologit        feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year==2018
svy: mlogit        feaffFAVOR01 dem01 female Rwhite Rblack age01 educ01 if year==2018

svy: reg           feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year==2018
margins, atmeans at(lib01=(0(1)1)) 
svy: fracreg logit feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year==2018
svy: ologit        feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year==2018
svy: mlogit        feaffFAVOR01 lib01 female Rwhite Rblack age01 educ01 if year==2018

* No controls

logit      fejobFAVOR2 dem01 if year>=2000 & year<=2018
svy: logit fejobFAVOR2 dem01 if year>=2000 & year<=2018
margins, atmeans at(dem01=(0(1)1))

logit      fejobFAVOR2 dem01 if year==2018
svy: logit fejobFAVOR2 dem01 if year==2018
margins, atmeans at(dem01=(0(1)1))

logit      fejobFAVOR2 lib01 if year>=2000 & year<=2018
svy: logit fejobFAVOR2 lib01 if year>=2000 & year<=2018
margins, atmeans at(lib01=(0(1)1))

logit      fejobFAVOR2 lib01 if year==2018
svy: logit fejobFAVOR2 lib01 if year==2018
margins, atmeans at(lib01=(0(1)1))

* Alternative method
gen strongDEMstrongGOP = partyid
recode strongDEMstrongGOP (0=1) (6=0) (1/5 7=.)
tab partyid strongDEMstrongGOP, mi

logit      fejobFAVOR2 strongDEMstrongGOP female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
svy: logit fejobFAVOR2 strongDEMstrongGOP female Rwhite Rblack age01 educ01 if year>=2000 & year<=2018
margins, atmeans at(strongDEMstrongGOP=(0(1)1))

logit      fejobFAVOR2 strongDEMstrongGOP female Rwhite Rblack age01 educ01 if year==2018
svy: logit fejobFAVOR2 strongDEMstrongGOP female Rwhite Rblack age01 educ01 if year==2018
margins, atmeans at(strongDEMstrongGOP=(0(1)1))
